<?php
/**
 * 问题控制器类
 */
namespace Admin\Controller;
use Think\Controller;

class QuestionController extends CommonController
{
    public function question_list()
    {
        $this->display();
    }
    // 问题分类
    public function category()
    {
        $category = M('qcategory')->select();
        $this->assign('category', $category);
        $this->display();
    }
    // 添加问题分类
    public function cate_add()
    {
        $post_data = I('post.data');
        $table = 'qcategory';
        $old_data = 0;
        $list = $this->adddata($table, $post_data);
        if ($list) {
            $list['url'] = U('admin/question/cate_edit', array('cag_id'=>$list['id'],'key'=>0));
            $info['type'] = 1;
            $info['data'] = $list;
            $log_info = [0=>$old_data, 1=>$post_data];
            $this->log('问题分类', $log_info, 2);
        } else {
            $info['type'] = 0;
        }
        $this->ajaxReturn($info);
    }
    // 编辑问题分类
    public function cate_edit()
    {
        $get_data = I('get.');
        $post_data = I('post.data');
        if ($get_data != null) {
            $list = M('qcategory')->where('cag_id='.$get_data['cag_id'])->find();
            $this->assign('list', $list);
            $this->assign('key', $get_data['key']);
            $this->display();
        } elseif($post_data != null) {
            $table = 'qcategory';
            $old_data = M($table)->where('cag_id='.$post_data['cag_id'])->find();
            $edit['cag_id'] = $post_data['cag_id'];
            $edit['category'] = $post_data['category'];
            $edit['fid'] = $post_data['fid'];
            $where = 'cag_id='.$post_data['cag_id'];
            $info = $this->editdata($table, $edit, $where);
            if ($info && $info['type'] == 1) {
                $log_info = [0=>$old_data, 1=>$post_data];
                $this->log('问题分类', $log_info, 3);
                $info['key'] = $post_data['key'];
            }
            $this->ajaxReturn($info);
        }
    }

    public function cate_del()
    {
        # code...
    }

    public function question_edit()
    {
        $this->display();
    }

    public function question_del()
    {
        $this->display();
    }
}
